home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 September
/
PCWorld_2006-09_cd.bin
/
v cisle
/
hexer
/
mpth_17.exe
/
{app}
/
scripts
/
Extract strings.mps
< prev
next >
Wrap
Text File
|
2006-03-19
|
6KB
|
219 lines
INCLUDE 'def.mps'
INCLUDE 'gui.mps'
option GlobalVars, 1
option ReadTags, 0
OPTION UNDO, 0
option target, structureviewer
DEF myregkey envparse("%appregkey%\\extract strings")
call DEC_TEXT_CONV
var charset dword := ansi, ascii7, unicode, ebcdic...
var minlen byte := minimum length of a string to be found
var charstouse text := characters to treat as "textual"
var charstostart text := characters to treat as "textual" on start of word
var limit dword := max. amount of strings on a page
var startpos qword := starting position
var cur file := current file
var alphasort byte := do alpha sorting?
INCLUDE '*.lng'
cur = fileopen('::current', 'r')
startpos = filegetprop(cur, 'SelStart'):= get current cursor position
fileclose cur
==== show dialog
@@dialog
call readoptions
if (GuiExists('dlgExtract'))
GuiDestroy('dlgExtract')
endif
call create_form
= select current combo item
var b1 qword
b1 = -1
ifgoto charset TEXTCONVERT_ANSI, ccb0, TEXTCONVERT_DOS8, ccb1, TEXTCONVERT_ASCII7, ccb2, TEXTCONVERT_MAC, ccb3, TEXTCONVERT_EBCDIC, ccb4, TEXTCONVERT_UNICODE, ccb5, TEXTCONVERT_UNICODEBE, ccb6, TEXTCONVERT_CUSTOM, ccb7, (TEXTCONVERT_CUSTOM-1), ccb8
goto ccbset
@@ccb0:b1=0:goto ccbset
@@ccb1:b1=1:goto ccbset
@@ccb2:b1=2:goto ccbset
@@ccb3:b1=3:goto ccbset
@@ccb4:b1=4:goto ccbset
@@ccb5:b1=5:goto ccbset
@@ccb6:b1=6:goto ccbset
@@ccb7:b1=7:goto ccbset
@@ccb8:b1=8
@@ccbset
GuiSetProp('dlgExtract.cbEncoding', 'ItemIndex', b1)
b1 = GUIShowModal('dlgExtract'):= show form in modal state
if b1 == IDOK
= do extraction
call doextract
endif
end
@@check_settings:= assure valid settings
var t1 text t2 text t3 text t4 text t5 text
t1 = GuiGetProp('dlgExtract.edChars', 'Text')
t2 = call('checkchars', t1)
if (t2 != '')
msgbox (__INVCHAR__+t2), MB_ICONSTOP
= cancel closing
GuiSetProp('dlgExtract', 'ModalResult', 0)
GuiSetProp('dlgExtract.edChars', 'Focused', True)
GuiSetProp('dlgExtract.edChars', 'SelStart', (TextPos(TextUpper(t2),TextUpper(t1))-1))
GuiSetProp('dlgExtract.edChars', 'SelLength', TextLen(t2))
return
endif
t5 = t1
t1 = GuiGetProp('dlgExtract.edStart', 'Text')
t2 = call('checkchars', t1)
if (t2 != '')
msgbox (__INVCHAR__+t2), MB_ICONSTOP
= cancel closing
GuiSetProp('dlgExtract', 'ModalResult', 0)
GuiSetProp('dlgExtract.edStart', 'Focused', True)
GuiSetProp('dlgExtract.edStart', 'SelStart', (TextPos(TextUpper(t2),TextUpper(t1))-1))
GuiSetProp('dlgExtract.edStart', 'SelLength', TextLen(t2))
return
endif
t2 = GuiGetProp('dlgExtract.edMinLen', 'Text')
if (not isnumber(t2))
msgbox (__INVNUM__+t2), MB_ICONSTOP
= cancel closing
GuiSetProp('dlgExtract', 'ModalResult', 0)
GuiSetProp('dlgExtract.edMinLen', 'Focused', True)
return
endif
t3 = GuiGetProp('dlgExtract.edLimit', 'Text')
if (not isnumber(t3))
msgbox (__INVNUM__+t3), MB_ICONSTOP
= cancel closing
GuiSetProp('dlgExtract', 'ModalResult', 0)
GuiSetProp('dlgExtract.edLimit', 'Focused', True)
return
endif
b1 = GuiGetProp('dlgExtract.cbEncoding', 'ItemIndex')
if (b1 == -1)
= cancel closing
GuiSetProp('dlgExtract', 'ModalResult', 0)
GuiSetProp('dlgExtract.cbEncoding', 'Focused', True)
return
endif
== get values
charstouse = t5
charstostart = t1
minlen = dword(t2)
limit = dword(t3)
alphasort = GuiGetProp('dlgExtract.cbAlphaSort', 'Checked')
if (not GuiGetProp('dlgExtract.cbCurPos', 'Checked'))
startpos = 0
endif
ifgoto b1 0, ccg0, 1, ccg1, 2, ccg2, 3, ccg3, 4, ccg4, 5, ccg5, 6, ccg6, 7, ccg7,8, ccg8
goto ccbset
@@ccg0:charset=TEXTCONVERT_ANSI:goto ccgset
@@ccg1:charset=TEXTCONVERT_DOS8:goto ccgset
@@ccg2:charset=TEXTCONVERT_ASCII7:goto ccgset
@@ccg3:charset=TEXTCONVERT_MAC:goto ccgset
@@ccg4:charset=TEXTCONVERT_EBCDIC:goto ccgset
@@ccg5:charset=TEXTCONVERT_UNICODE:goto ccgset
@@ccg6:charset=TEXTCONVERT_UNICODEBE:goto ccgset
@@ccg7:charset=TEXTCONVERT_CUSTOM:goto ccgset
@@ccg8:charset=(TEXTCONVERT_CUSTOM-1)
@@ccgset
== store values
regwrite myregkey, "charset", charset
regwrite myregkey, "minlen", minlen
regwrite myregkey, "limit", limit
regwrite myregkey, "charstouse", charstouse
regwrite myregkey, "charstostart", charstostart
regwrite myregkey, "alphasort", alphasort
return
@@checkchars
var test text res text
pop test
test = textupper(test)
res = ''
var i dword
i = 1
while (i < textlen(test))
if (textcopy(test,i,1) != '?')
inc i,1
else
res = textcopy(test,i,3)
inc i,3
ifgoto res, "?HT", cc1, "?QM", cc1, "?VT", cc1, "?FF", cc1, "?LF", cc1, "?CR", cc1, "?SP", cc1
if (textcopy(res,1,2) != '?X')
return res
endif
res = res+textcopy(test,i,3)
if (not ishex(textcopy(res, 3,4)))
return res
endif
inc i,3
@@cc1:
res=''
endif
endwhile
return res
@@showcharsinfo:= show accepted characters info
msgbox __INFOAC__, MB_ICONINFORMATION, __INFOACT__
return:= could also be the END command as the script cannot be terminated in a event handler!
= read options from registry
@@readoptions
IF (not REGREAD(myregkey, "charset", @charset))
charset = (TEXTCONVERT_CUSTOM-1) := if set to (TEXTCONVERT_CUSTOM-1), use charset of the open file
ENDIF
IF (not REGREAD(myregkey, "minlen", @minlen))
minlen = 4 := at least four characters to form a string
ENDIF
IF (not REGREAD(myregkey, "limit", @limit))
limit = 100 := max 100 strings per page
ENDIF
IF (not REGREAD(myregkey, "charstouse", @charstouse))
charstouse = "?HT?LF?VT?FF?CR?SP!"+'"'+"#$%&'()*+,-./0123456789:;<=>?QM@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~Çó"
ENDIF
IF (not REGREAD(myregkey, "charstostart", @charstostart))
charstostart = "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
ENDIF
IF (not REGREAD(myregkey, "alphasort", @alphasort))
alphasort = 0
ENDIF
return
@@do_from:= called from html
call readoptions
var t text
pop t:= name of the parameter
pop t:= value of the parameter
startpos = dword(t)
@@doextract
= call the plugin (located in the tiny hexer root directory)
!Cmd.ToolsStructureViewer, 1
!PLUGIN ENVPARSE('%apppath%\extractstrings.ths'), "::current", charset, minlen, charstouse, limit, startpos, charstostart, alphasort
return